<?php

if (!defined('_PAGE_'))
    include _FLEP_LIB_DIR_.'/page.inc';

$css = array('main.css', 'estudiante.css', 'detalle_estudiante.css');
$javascript = array('common.js', 'estudiante.js', 'ajax.js', 'inscripcion.js', 'search.js');

$structure = flep_page_init('curso');

flep_structure($estudiante, 'estudiante');

if(isset($_GET['id'])){
    $estudiante['where'][0] = sprintf("`estudiantes`.`id`='%s'", flep_decode($_GET['id']));
} else {
    header('Location: main.php?page=estudiante');
}

$structure['estudiante'] = &$estudiante;

function include_page(&$structure){

$user = &$_SESSION['user'];
$estudiante = &$structure['estudiante'];
?>
    <h3><a href="main.php?page=curso">Inscribir</a></h3>
    <br>
    <div class="menu">
        <a href="?page=add_curso">Agregar</a>&nbsp;|&nbsp;
        <a href="">Pago</a>&nbsp;|&nbsp;
        <a href="">Inscripcion</a>&nbsp;|&nbsp;
        <a href="">Subir Notas</a>&nbsp;|&nbsp;
        <?php flep_page_search($estudiante); ?>
    </div>
    <br><b><?php
        flep_page_message();
        flep_search_all($estudiante);
?></b>
    <table class="header">
        <tbody>
            <tr><th colspan="4"><?php echo $estudiante['data'][0]['categoria']; ?></th></tr>
            <tr><td><?php echo strtoupper($estudiante['data'][0]['usuario']); ?></td><td colspan="3"><?php echo $estudiante['data'][0]['nombre']; ?></td></tr>
            <tr><td colspan="4">&nbsp;</td></tr>
            <tr><th>Telefono:</th><td><?php echo $estudiante['data'][0]['telefono']; ?></td><th>Activo:</th><td><img src="img/<?php echo $estudiante['data'][0]['activo']?'ok':'close'; ?>.png"></td></tr>
            <tr><th>Correo Electronico:</th><td><?php echo $estudiante['data'][0]['correo']; ?></td></tr>
        </tbody>
    </table>
    <br><b>
<?php
        flep_page_navigation($structure);
    ?></b><br>
    <p></p>
    <table class="list">
        <thead><tr><th>N&deg;</th><?php
            foreach($structure['fields'] as &$field){
                printf('<th>%s</th>', $field['title']);
            }
            unset($field);
        ?>
        <th></th>
        </tr></thead>
        <tfoot>
            <tr><th colspan="<?php echo count($structure['fields']) + 2;?>"></th></tr>
        </tfoot>
        <tbody><?php
            if(flep_search_all($structure)){
                for($i = 0; $i < count($structure['data']); $i++){
                    printf('<tr><td>%s</td>', $structure['offset'] + $i+1);
                    foreach($structure['fields'] as $id => &$field){
                        switch ($field['type']) {
                            case 'text':
                            case 'number':
                                printf('<td title="%s">%s</td>', $field['title'], $structure['data'][$i][$id]);
                                break;
                            case 'list':
                                printf('<td title="%s">%s</td>', $field['title'], ($id === 'docente_id' ? $structure['data'][$i]['nombre'] : $structure['data'][$i][substr($id, 0, strlen($id) - 3)]));
                                break;
                            case 'bool':
                                printf('<td title="%s" style="padding: 0px; text-align: center;"><img src="img/%s.png" title="%s"></td>', $field['title'], ($structure['data'][$i][$id]?'ok':'close'), ($structure['data'][$i][$id]?'Activo':'Inactivo'));
                                break;
                            default:
                                break;
                        }
                    }
                    printf('<td style="text-align:center;padding:0px;"><img src="img/inscripcion.png" title="Inscribir" onclick="flep_inscribir(\'%s\',\'%s\')"></td></tr>', flep_encode($structure['data'][$i]['id']), flep_encode($estudiante['data'][0]['id']));
                }
            }else{
                printf('<tr><td colspan="%s">No se encontraron cursos - Haga click en Agregar.</td></tr>', count($structure['fields'])+2);
            }
        ?></tbody>
    </table>
<?php
}

function include_menu(){
    include_main_menu();
}

?>
